package com.tobestronger.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class ListValueConstraintValidator implements ConstraintValidator<ListValue,Integer> {

    private Set<Integer> valsSet = new HashSet<>();

    @Override
    public void initialize(ListValue constraintAnnotation) {
        //ConstraintValidator.super.initialize(constraintAnnotation);
        Arrays.stream(constraintAnnotation.vals())
                .forEach(item->{

                    valsSet.add(item);
                });

    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        return valsSet.contains(value);
    }
}
